package com.x.erp.manage;

import com.x.erp.model.ImageView;
import com.x.erp.model.ImageViewType;
import com.x.framework.manage.BaseManage;
import org.springframework.stereotype.Service;

@Service
public class ImageViewManage extends BaseManage {

    public ImageView insertImageView(ImageView imageView, String[] imageViewTypeList) throws Exception {
        this.insert(imageView);
        if (imageViewTypeList != null && imageViewTypeList.length > 0){
            ImageViewType imageViewType = new ImageViewType();
            for (String imageViewType1 :imageViewTypeList) {
                imageViewType.setImageViewId(imageView.getImageViewId());
                imageViewType.setImageViewKey(imageViewType1);
                this.insert(imageViewType);
            }
        }
        return imageView;
    }

    public int updateImageView(ImageView imageView, String[] imageViewTypeList) throws Exception {
        if (imageViewTypeList != null && imageViewTypeList.length > 0){
            ImageViewType imageViewType = new ImageViewType();
            imageViewType.setImageViewId(imageView.getImageViewId());
            this.delete(imageViewType);
            for (String imageViewType1 :imageViewTypeList) {
                imageViewType.setImageViewId(imageView.getImageViewId());
                imageViewType.setImageViewKey(imageViewType1);
                this.insert(imageViewType);
            }
        }
        return this.update(imageView);
    }
}
